Conditions | 7 |
Paths | 12 |
Total Lines | 95 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import path from 'path' |
||
80 | var route = function(req, res, next) { |
||
81 | var filePath = req.originalUrl.replace('/abe/editor', '') |
||
82 | if (filePath === '' || filePath === '/') { |
||
83 | filePath = null |
||
84 | } |
||
85 | |||
86 | if(filePath != null){ |
||
87 | var testXSS = xss(filePath, { |
||
88 | whiteList: [], |
||
89 | stripIgnoreTag: true |
||
90 | }) |
||
91 | if(testXSS !== filePath){ |
||
92 | filePath = testXSS |
||
93 | } |
||
94 | } |
||
95 | |||
96 | abeExtend.hooks.instance.trigger('beforeRoute', req, res, next) |
||
97 | if(typeof res._header !== 'undefined' && res._header !== null) return |
||
98 | |||
99 | var isHome = true |
||
100 | var jsonPath = null |
||
101 | var linkPath = null |
||
102 | var template = null |
||
103 | var fileName = null |
||
104 | var folderPath = null |
||
105 | |||
106 | var EditorVariables = { |
||
107 | user: res.user, |
||
108 | slugs: Manager.instance.getSlugs(), |
||
109 | express: { |
||
110 | res: res, |
||
111 | req: req |
||
112 | }, |
||
113 | filename: fileName, |
||
114 | folderPath: folderPath, |
||
115 | abeUrl: '/abe/editor/', |
||
116 | isHome: isHome, |
||
117 | config: config, |
||
118 | Locales: coreUtils.locales.instance.i18n, |
||
119 | abeVersion: pkg.version |
||
120 | } |
||
121 | |||
122 | let p = new Promise((resolve) => { |
||
123 | |||
124 | if(filePath != null) { |
||
125 | fileName = path.basename(filePath) |
||
126 | folderPath = path.dirname(filePath) |
||
127 | |||
128 | EditorVariables.isHome = false |
||
129 | var filePathTest = cmsData.revision.getDocumentRevision(filePath) |
||
130 | if(typeof filePathTest !== 'undefined' && filePathTest !== null) { |
||
131 | jsonPath = filePathTest.path |
||
132 | linkPath = filePathTest.abe_meta.link |
||
133 | template = filePathTest.abe_meta.template |
||
134 | } |
||
135 | |||
136 | if(jsonPath === null || !coreUtils.file.exist(jsonPath)) { |
||
137 | res.redirect('/abe/editor') |
||
138 | return |
||
139 | } |
||
140 | |||
141 | var json = {} |
||
142 | if(coreUtils.file.exist(jsonPath)) { |
||
143 | json = cmsData.file.get(jsonPath, 'utf8') |
||
144 | } |
||
145 | var text = cmsTemplates.template.getTemplate(template, json) |
||
146 | editor(text, json, linkPath) |
||
147 | .then((result) => { |
||
148 | resolve(result) |
||
149 | }).catch(function(e) { |
||
150 | console.error(e) |
||
151 | }) |
||
152 | }else { |
||
153 | resolve({ |
||
154 | json: {}, |
||
155 | manager: {} |
||
156 | }) |
||
157 | } |
||
158 | }).catch(function(e) { |
||
159 | console.error(e) // "oh, no!" |
||
160 | }) |
||
161 | |||
162 | p.then((obj) => { |
||
163 | var precontrib = Manager.instance.getPrecontribution() |
||
164 | editor(precontrib.template, obj.json, '', true) |
||
165 | .then((resultPrecontrib) => { |
||
166 | EditorVariables.resultPrecontrib = resultPrecontrib |
||
167 | renderAbeAdmin(EditorVariables, obj, filePath, isHome, template) |
||
168 | }).catch(function(e) { |
||
169 | console.error(e) |
||
170 | }) |
||
171 | }).catch((e) => { |
||
172 | console.log('error', e) |
||
173 | }) |
||
174 | } |
||
175 | |||
177 |